package com.controller;

import com.model.DaoHang;
import com.model.MyEcharts;
import com.model.MyNode;
import com.model.MyUser;
import com.service.MyUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Api(tags = "我的用户")
@RestController
@RequestMapping("/myUser")
public class MyUserController {

    @Autowired
    private MyUserService myUserService;

    @CrossOrigin
    @RequestMapping(value = "/addUser", produces = "application/json;charset=utf-8", method = RequestMethod.PUT)
    public int addUser(@RequestBody MyUser myUser){
        System.out.println("进入用户添加方法");
        return myUserService.addMyUser(myUser);
    }

    @CrossOrigin
    @RequestMapping(value = "/updateMyUser", produces = "application/json;charset=utf-8", method = RequestMethod.PUT)
    public int updateUser(@RequestBody MyUser myUser){
        System.out.println("进入用户修改方法，修改的主键为"+ myUser.getUserId());
        return myUserService.updateMyUser(myUser);
    }

    @CrossOrigin
    @RequestMapping(value = "/deleteMyUser", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    public int deleteMyUser(int userId){
        System.out.println("进入删除用户信息，主键为："+ userId);
        return myUserService.deleteMyUser(userId);
    }

    @CrossOrigin
    @RequestMapping(value = "/getUser", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    public MyUser getUser(int userId){
        System.out.println("进入根据主键查找用户信息，主键为："+ userId);
        return myUserService.getUser(userId);
    }

    @CrossOrigin
    @RequestMapping(value = "/getAll", produces = "application/json;charset=utf-8", method = RequestMethod.PUT)
    public List<MyUser> getAll(@RequestBody MyUser myUser){
        System.out.println("进入用户查询方法");
        System.out.println(myUser.getUserName() + "=====" + myUser.getPwd());
        List<MyUser> myUserList=myUserService.getAllMyUsers(myUser);
        System.out.println(myUserList.size());
        return myUserService.getAllMyUsers(myUser);
    }

    @CrossOrigin
    @ApiOperation(value = "获取用户状态分析信息")
    @RequestMapping(value = "/getEcharts", produces = "application/json;charset=utf-8", method = RequestMethod.PUT)
    public List<MyEcharts> getEcharts(@RequestBody MyUser myUser){
        System.out.println("进入用户分析方法");
        System.out.println(myUser.getUserName());
        List<MyEcharts> myEcharts=myUserService.EchartsMyUserStart(myUser);
        System.out.println(myEcharts.size());
        return myEcharts;
    }
}

